/*************************************************************************
> File Name: 004.c
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-07-24 16:15:31
> Description: 将数组前n个元素反序
************************************************************************/
#define SIZE 20
#include <stdio.h>
void swap(int *num1, int *num2);
void safeScanfInt(int *i);
int main(int argc, char const *argv[])
{
    int arr[SIZE] = {0};
    int range = 0;
    for (int i = 0; i < SIZE; i++)
    {
        arr[i] = i + 1;
    }
    printf("An array of 1-%d is generated, enter the range in reverse order\n", SIZE);
    safeScanfInt(&range);
    if (range > SIZE)
    {
        range = SIZE;
        printf("voer arr bounds! set range max ,range = %d\n", range);
    }
    for (int i = 0; i < range / 2; i++)
    {
        swap(arr + i, arr + range - i - 1);
    }
    printf("the orginal arr is:");
    for (int i = 0; i < SIZE; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
    printf("the new arr is:");
    for (int i = 0; i < SIZE; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");
    return 0;
}
void safeScanfInt(int *i)
{
    scanf("%*[^0-9]");
    scanf("%d*[^\n]%*c", i);
}
void swap(int *num1, int *num2)
{
    if (num1 != num2)
    {
        *num1 = *num1 ^ *num2;
        *num2 = *num1 ^ *num2;
        *num1 = *num1 ^ *num2;
    }
}
